﻿#ifndef CRCCHECK_H
#define CRCCHECK_H

#include <QByteArray>

class crcCheck
{
public:
    /* crc-8的计算 */
    static uint8_t calculate_crc8(const QByteArray &data, uint8_t poly = 0x07, uint8_t init = 0x00);
    static uint8_t calculate_crc8(const uint8_t *data, int length, uint8_t poly = 0x07, uint8_t init = 0x00);

    /* crc-32的计算 */
    static uint32_t calculate_crc32(const QByteArray &data, uint32_t poly = 0x04C11DB7, uint32_t init = 0xFFFFFFFF, uint32_t xorOut = 0xFFFFFFFF, bool refIn = true, bool refOut = true);
    static uint32_t calculate_crc32(const uint8_t *data, int length, uint32_t poly = 0x04C11DB7, uint32_t init = 0xFFFFFFFF, uint32_t xorOut = 0xFFFFFFFF, bool refIn = true, bool refOut = true);

private:
    static uint32_t reflect(uint32_t value, int bits);
};

#endif // CRCCHECK_H
